using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OutsiderPointerPool : MonoBehaviour
{
    public static List<GameObject> listOfGo_OutsiderPointer;
    public static GameObject player;
    public static GameObject pool;
    static OutsiderPointerPool(){
        listOfGo_OutsiderPointer = new List<GameObject>();
    }

    // 这个方法用于在本机车辆产生后, 调用 StartMonitor
    // 从而让其他所有的OutsiderPointer开始工作
    public static void StartMonitor(GameObject player){
        OutsiderPointerPool.player = player;
    }

    public static void AddOutsiderPointer(GameObject from, GameObject to){
        pool.GetComponent<OutsiderPointerPool>().Add(from, to);
    }


    [Header("手动设置")]
    public GameObject prefab_OutsiderPointer;    

    private void Start() {
        OutsiderPointerPool.pool = gameObject;
    }
    public void Add(GameObject from, GameObject to){
        
        Debug.Log("Create OutsiderPointer");
        GameObject tmp = GameObject.Instantiate(prefab_OutsiderPointer);
        tmp.transform.SetParent(transform);
        OutsiderPointer pointer = tmp.GetComponent<OutsiderPointer>();
        Debug.Log(from);
        Debug.Log(to);
        pointer.go_PointerTo = to;
        if (from==null)
            pointer.go_PointerFrom = OutsiderPointerPool.player;
        else
            pointer.go_PointerFrom = from;
        pointer.Show(false);
    }
}
